import { userAPI } from '@/api/user'
export default {
  namespaced: true,
  state () {
    return {
      token: localStorage.getItem('token') || '',
      userInfo: {}
    }
  },
  mutations: {
    // 设置token
    setToken (state, token) {
      state.token = token
      localStorage.setItem('token', token)
    },
    // 设置用户信息
    setUserInfo (state, userInfo) {
      state.userInfo = userInfo
    },
    // 清空token
    clearToken (state) {
      state.token = ''
      localStorage.removeItem('token')
    }
  },
  actions: {
    async reqUserInfo (ctx) {
      const res = await userAPI()
      // console.log(res)
      ctx.commit('setUserInfo', res.data)
    }
  },
  getters: {}
}
